
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		
	    log using polity4_prep, replace t


* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Mena Economic Monitor, Fall 2016 edition (MNACE, The World Bank)


* This do file prepares the Polity4 database for merge

* Database used : p4v2015.xls


* Output : polity4.dta

* ------------------------------------------------------------------------------


*                      ---------------------------
*                      ----------POLITY4 Data---------
*                      ---------------------------


import excel using "${datadir}/p4v2015.xls", firstrow clear

* Labeling Variables

label variable cyear "Country Year (p4)"
label variable ccode ""
label variable ccode "Numeric Country Code"
label variable scode "Alpha Country Code"
label variable country "Alpha Country Name"
label variable year "Year Coded (p4)"
label variable flag "Tentative Coding (p4)"
label variable fragment "Polity Fragmentation (p4)"
label variable democ "Institutionalized Democracy"
label variable autoc "Institutionalized Autocracy"
label variable polity "Combined Polity Score"
label variable polity2 "Revised Combined Polity Score (p4)"
label variable durable "Regime Durability (p4)"
label variable xrreg "Regulation of Chief Executive Recruitment"
label variable xrcomp "Competitiveness of Executive Recruitment"
label variable xropen "Openness of Executive Recruitment"
label variable xconst "Executive Constraints (Decision Rules)"
label variable parreg "Regulation of Participation"
label variable parcomp "The Competitiveness of Participation"
label variable exrec "Executive Recruitment Concept"
label variable exconst "Executive Constraints Concept"
label variable polcomp "Political Competition Concept"
label variable prior "Prior Polity Code (p4)"
label variable emonth "Polity End Month"
label variable eday "Polity End Day"
label variable eyear "Polity End Year"
label variable eprec "End Date Precision"
label variable interim "Interim Polity Code (p4)"
label variable bmonth "Polity Begin Month"
label variable bday "Polity Begin Day"
label variable byear "Polity Begin Year"
label variable bprec "Begin Date Precision"
label variable post "Post Polity Code (p4)"
label variable change "Total change in POLITY value (p4)"
label variable d4 "Regime Transition Completed (p4)"
label variable sf "State Failure (p4)"
label variable regtrans "Regime Transition (p4)"

* Keeping years after 2004

keep if year>=2004

/* Polity4 data has info aval since 1800s. More careful categorization of countries
and their boundaries is required if we want to use the historical data. */

 
* Dropping countries that do not exist in WDI and Gallup

*drop if country=="Baden"
*drop if country=="Bavaria"
drop if country=="Cape Verde"
drop if country=="East Timor"
*replace country = "Czech Republic" if country=="Czechoslovakia"
drop if country=="Fiji"
*drop if country=="Germany East"
*drop if country=="Germany West"
*drop if country=="Gran Colombia"
*drop if country=="Korea"
replace country = "North Korea" if country=="Korea North"
replace country = "South Korea" if country=="Korea South"
*drop if country=="Modena"
*drop if country=="Orange Free State"
*drop if country=="Papal States"
drop if country=="Papua New Guinea"
*drop if country=="Parma"
*drop if country=="Prussia"
*drop if country=="Sardinia"
*drop if country=="Saxony"
drop if country=="Serbia and Montenegro"
drop if country=="Solomon Islands"
drop if country=="Sudan"
replace country = "Sudan" if country=="Sudan-North"
*drop if country=="Tuscany"
*drop if country=="Two Sicilies"
replace country = "United Arab Emirates" if country=="UAE"
*replace country = "Russia" if country=="USSR"
*drop if country=="Vietnam South"
*drop if country=="Vietnam North"
*drop if country=="Wuerttemburg"
*drop if country=="Yemen South"
*drop if country=="Yemen North"
drop if country=="Yugoslavia"
*drop if country=="United Province CA"

* Adding countries that are in WDI and gallup but not in polity4

insobs 9, before(1)
 replace country = "Belize" in 1
 replace year = 2005 in 1
 replace country = "Hong Kong" in 2
 replace year = 2005 in 2
 replace country = "Iceland" in 3
 replace year = 2005 in 3
 replace country = "Malta" in 4
 replace year = 2005 in 4
 replace country = "Nagorno Karabakh" in 5
 replace year = 2005 in 5
 replace country = "Northern Cyprus" in 6
 replace year = 2005 in 6
 replace country= "Puerto Rico" in 7
 replace year = 2005 in 7
 replace country = "Somaliland" in 8
 replace year = 2005 in 8
 replace country = "Palestine" in 9
 replace year = 2005 in 9

 
sort country, stable
encode country, gen(ctry)
sort ctry year


note: Keeping only unified Germany (polity4)
note: Keeping only S and N Korea (dropping observations before that time) (polity4)
note: Keeping sudan and south sudan after 2011 (polity4)
note: Keeping observations after 2004 (polity4)

save "${outdir}/polity4.dta", replace

log close
